function dailyTemperatures(arr) {
  let ans = []
  for (let i = 0; i < arr.length; i++) {
    let j = i + 1
    for (; j < arr.length; j++) {
      if (arr[j] > arr[i]) break
    }
    j == arr.length ? ans.push(0) : ans.push(j - i)
  }
  return ans
}


var dailyTemperatures = function (arr) {
  let ans = new Array(arr.length).fill(0)
  let stack = []
  for (let i = 0; i < arr.length; i++) {
    while (stack.length > 0 && arr[i] > arr[stack[stack.length - 1]]) {
      // 不再递减
      let top = stack.pop()
      ans[top] = i - top
    }
    stack.push(i)
  }
  return ans
}